package com.test.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.entity.Teacher;
import com.test.service.TeacherService;
import com.test.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/list")
    public ResponseResult<IPage<Teacher>> list(@RequestParam Integer page,
                                               @RequestParam Integer size) {
        Page<Teacher> pages =teacherService.pages(page,size);
        return ResponseResult.success(pages);
    }

    @DeleteMapping("/{id}")

    public ResponseResult<String> delete(@PathVariable Integer id) {
        teacherService.delete(id);
        return ResponseResult.success();
//        boolean removed = teacherService.removeById(id);
//        if (removed) {
//            redisUtil.del("teacher_page_1_10");
//            return ResponseResult.success("Deleted successfully");
//        } else {
//            return ResponseResult.failure("Failed to delete");
//        }
    }
}
